package com.ganee.agora.adapter

import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.chad.library.adapter.base.BaseQuickAdapter
import com.ganee.agora.R
import com.ganee.agora.manager.RecyclerViewHolder
import com.ganee.agora.model.HomeListBean
import com.ganee.baselib.widget.image.transform.GlideRoundTransform
import com.ganee.baselib.mvvmlibrary.widget.loadingdrawable.DensityUtil
import com.ganee.agora.manager.RoundedCornersTransform
import com.ganee.agora.model.InsertActivityEntity


/**
 *    @author : EricCui
 *    date   : 2020-01-01 17:52
 *    desc   : 收藏列表adapter
 */

class YourListAdapter (entityList: MutableList<InsertActivityEntity>) : BaseQuickAdapter<InsertActivityEntity,
        RecyclerViewHolder>(R.layout.item_recyclerview_your_list,entityList){


    override fun convert(helper: RecyclerViewHolder, item: InsertActivityEntity?) {
        if (item != null){
            val icon = helper.getView<ImageView>(R.id.item_list_iv_icon) as ImageView
            val transform = RoundedCornersTransform(mContext, DensityUtil.dip2px(mContext, 10F))
            transform.setNeedCorner(true, true, false, false)

            Glide.with(mContext)
                    .load(item.activePic)
                    .transform(GlideRoundTransform(mContext))
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .placeholder(R.drawable.home_placeholder)
                    .error(R.drawable.home_placeholder)
                    .into(icon)

            helper.setText(R.id.item_list_tv_title,item.eventTitle)


            var mMonth:String?= null
            //20200110 120000
            if(null != item.createTime){
                var month  = item.createTime.substring(4,6).toInt()
                val day  = item.createTime.substring(6,8)
                val hour = item.createTime.substring(8,10)
                val minute = item.createTime.substring(10,12)

                when(month){
                    1 -> mMonth = "Jan"
                    2 -> mMonth = "Feb"
                    3 -> mMonth = "Mar"
                    4 -> mMonth = "Apr"
                    5 -> mMonth = "May"
                    6 -> mMonth = "Jun"
                    7 -> mMonth = "Jul"
                    8 -> mMonth = "Aug"
                    9 -> mMonth = "Sept"
                    10 -> mMonth = "Oct"
                    11 -> mMonth = "Nov"
                    12 -> mMonth = "Dec"
                }

                var time:String = if (hour.toInt() >= 12){
                    hour + ":" + minute + "pm"
                } else {
                    hour + ":" + minute + "am"
                }

                helper.setText(R.id.item_list_tv_time, "$mMonth$day·$time")
                        .setText(R.id.item_list_tv_location,item.location)
                        .setText(R.id.item_list_tv_user,"posted by " + item.host)
            }
        }
    }

}